import {TOP_LIST} from '../api'
const defaultState ={
  list:[]
}



export default (state=defaultState,action)=>{
  switch(action.type){
    case 'INIT_LIST':
      return {...state,list:action.list}
    default:
      return state
  }
}


//加载所有的榜单

export const loadTopList =()=>(dispatch)=>{
  fetch(TOP_LIST).then((response)=>response.json()).then(result=>{
    console.log(result);
    let list = result.list.map(val=>{
      if(val.playCount>10000){
        val.playCount=parseInt(val.playCount/10000) + "万"
      }
      return val
    })
    
    dispatch({
      type:"INIT_LIST",
      list:list
    })
  })
 
}